package com.demo.core.controller;

import com.demo.base.model.company.CompanyInfo;
import com.demo.base.model.company.Score;
import com.demo.base.page.IPagableDTO;
import com.demo.base.page.PagableDTO;
import com.demo.base.util.CommonUtil;
import com.demo.core.service.CompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 公司信息
 * Created by jiandandia on 2017/4/6.
 */
@RequestMapping("/CompanyInfo")
@Controller
public class CompanyInfoController {
    @Autowired
    private CompanyInfoService companyInfoService;

    /**
     * 添加或更改公司信息
     */
    @ResponseBody
    @RequestMapping("/newOrupdateCompanyInfo")
    public String newOrupdateCompanyInfo(@RequestBody CompanyInfo companyInfo){
        try {
            companyInfoService.newOrupdateCompanyInfo(companyInfo);
        }catch (Exception e){
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * 根据id查询公司信息
     */
    @ResponseBody
    @RequestMapping("/getCompanyInfoById")
    public CompanyInfo getCompanyInfoById(@RequestBody CompanyInfo companyInfo){
        try {
            return companyInfoService.getCompanyInfoById(companyInfo.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    //根据公司简称查询获取公司信息
    @ResponseBody
    @RequestMapping("/getCompanyInfoByQuery")
    public IPagableDTO<CompanyInfo> getCompanyInfoByQuery(@RequestBody String companyName, int startRow, int pageSize){

            IPagableDTO pagableDTO = new PagableDTO();
            pagableDTO.setStartRow(startRow);
            pagableDTO.setPageSize(pageSize);
            return companyInfoService.getCompanyInfoByQuery(companyName, pagableDTO);
    }

    //删除单条或多条公司信息
    @ResponseBody
    @RequestMapping("/delteCompanyInfoById")
    public String delteCompanyInfoById(@RequestBody String ids){
        try{
            companyInfoService.delteCompanyInfoById(ids);
        }catch(Exception e){
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }

    /**
     * 添加公司评分或招聘信息评分
     */
    @ResponseBody
    @RequestMapping("/newCompanyInfoScore")
    public String newCompanyInfoScore(@RequestBody Score score){
        try {
            companyInfoService.newCompanyInfoScore(score);
        }catch (Exception e){
            return CommonUtil.FAIL;
        }
        return CommonUtil.SUCCESS;
    }
}
